package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

func main() {
	file, err := os.OpenFile("./2.txt", os.O_WRONLY, 0666)
	if err != nil {
		fmt.Println(err)
	}
	str := "hello world,I am line "
	writer := bufio.NewWriter(file)
	var str1 string
	for i := 0; i < 5; i++ {
		str1 = str + strconv.FormatInt(int64(i)+1, 10)
		writer.WriteString(str1)
		writer.WriteString("\r\n")
	}
	writer.Flush()
	file.Close()
	file1, _ := os.Open("./2.txt")
	reader := bufio.NewReader(file1)
	for {
		line, err2 := reader.ReadString('\n')
		if err2 == io.EOF {
			break
		}
		fmt.Print(line)
	}
	file1.Close()
}
